﻿using UnityEngine;
using System.Collections;
using XLua;

public class TimeSample
{
    private static int CurTickCount = 0;
    private static int InteractionTimes = 0;
    public static void Begin(int interactionTimes)
    {
        InteractionTimes = interactionTimes;
        LuaService.Instance.LuaEnv.DoString("InteractionTimes = " + interactionTimes);
        CurTickCount = System.Environment.TickCount;
    }

    public static void End()
    {
        Debug.Log("每百万次耗时:" + (System.Environment.TickCount - CurTickCount) * 1000000.0/InteractionTimes);
        CurTickCount = System.Environment.TickCount;
    }

}

public class MemorySample
{
    private static int CurMemoryCount = 0;
    private static int InteractionTimes = 0;
    public static void Begin(int interactionTimes)
    {
        InteractionTimes = interactionTimes;
        LuaService.Instance.LuaEnv.DoString("InteractionTimes = " + interactionTimes);
        LuaService.Instance.LuaEnv.DoString(@" 
           collectgarbage('collect')
           CurMemoryCount = collectgarbage('count')
        ");
//        LuaService.Instance.LuaEnv.Global.Get("CurMemoryCount", out CurMemoryCount);
    }


    public static void End()
    {
        int cur = CurMemoryCount;
//        LuaService.Instance.LuaEnv.Global.Get("CurMemoryCount", out CurMemoryCount);
//        Debug.Log("每百万次内存:" + (CurMemoryCount - cur) * 1000000 / InteractionTimes);
        LuaService.Instance.LuaEnv.DoString(@"
        local new = collectgarbage('count')
        print('每百万次内存'..new - CurMemoryCount)
        CurMemoryCount = new
        ");
    }
}
